<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small"  :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目编码"  prop="projectNo">
        <el-input v-model.trim="queryParams.projectNo" @change="handleQuery" placeholder="请输入项目编码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称"  prop="productName">
        <el-input v-model.trim="queryParams.productName" @change="handleQuery"  placeholder="请输入产品名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="任务编号" prop="taskNo">
        <el-input v-model.trim="queryParams.taskNo" @change="handleQuery"  placeholder="请输入任务编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否超期" prop="overdue">
        <el-select v-model="queryParams.overdue" filterable clearable  @change="handleQuery"  >
          <el-option v-for="dict in dict.type.project_task_overdue" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="产品类型" prop="productType">
        <el-select v-model="queryParams.productType" filterable clearable  @change="handleQuery" >
          <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="产品线" prop="productLine">
        <el-select v-model="queryParams.productLine" filterable clearable  @change="handleQuery" >
          <el-option v-for="dict in dict.type.product_line" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"   @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-radio-group v-model="activeName" @change="handleClick">
      <el-radio-button :label="0" >{{ this.unDoneNum }}</el-radio-button>
      <el-radio-button :label="1" >{{ this.rejectNum }}</el-radio-button>
      <el-radio-button :label="2" >{{ this.doingNum }}</el-radio-button>
      <el-radio-button :label="3" >{{ this.doneNum }}</el-radio-button>
    </el-radio-group>


     <el-table border v-loading="loading" :data="taskList" :border="false"  header-cell-class-name="table_header_row">

      <el-table-column label="超期天数"  align="center" prop="overdueNum">
        <template slot-scope="scope">
          <el-tag  type="danger"  v-if="scope.row.overdue > 0">{{scope.row.overdue}}天</el-tag>
          <el-tag  v-else>未超期</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="任务编号" align="center" prop="taskNo" width="150"/>
      <el-table-column label="项目编码" align="left"  width="150"  prop="projectNo">
        <template slot-scope="scope">
          <a style="color: cornflowerblue;" @click="openViewDetail(scope.row)">{{ scope.row.projectNo }}</a>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" width="150"/>
      <el-table-column label="产品名称" align="center" prop="productName" width="150"/>
      <el-table-column label="产品类型" :show-overflow-tooltip="true" align="center" prop="productType"  width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_type" :value="scope.row.productType" />
        </template>
      </el-table-column>
      <el-table-column label="产品线" :show-overflow-tooltip="true" align="center" prop="productLine"  width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_line" :value="scope.row.productLine" />
        </template>
      </el-table-column>
      <el-table-column label="项目经理" align="center" prop="projectManagerName" />
      <el-table-column label="任务名称" align="center" prop="nodeName" width="300"/>
      <el-table-column label="开始时间" align="center" prop="startTime"  width="100"/>
      <el-table-column label="结束时间" align="center" prop="endTime"  width="100" />
      <el-table-column label="是否完成" :show-overflow-tooltip="true" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_task_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="责任人" align="center" prop="nickName"   width="150"/>
      <el-table-column label="OA单号" align="center" prop="oaNo"   width="150"/>
      <el-table-column label="完成时间" align="center" prop="workEndTime"  width="100"/>
      <el-table-column label="用时" align="center" prop="dayNum"  width="100"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="220">
        <template slot-scope="scope"> 
           <el-button size="small"  type="primary"  v-hasPermi="['projectManage:list:bindPLM']"   @click="handleRePLMFile(scope.row)" v-show="scope.row.status == 0">关联PLM文档</el-button> 
           <el-button size="small"  type="warning"  v-hasPermi="['projectManage:list:bindPLM']"  icon="el-icon-edit"  @click="handleRePLMFile(scope.row)" v-show="scope.row.type  == 20 && scope.row.status == 10">文档变更</el-button> 
        </template>
      </el-table-column> 
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

      
    <!--绑定PLM文件弹框-->
    <bind-plm-file ref="bindPlmFile"></bind-plm-file>

  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {getTaskList,processAdd}  from "@/api/projectManage/task";
import bindPlmFile  from "@/components/projectManage/list/bindPLMFile";


export default {
  name: "SearchTaskList",
  components: { bindPlmFile },
  dicts: ['project_task_overdue','project_task_status','product_line','product_type'],
  data() {
    return {
      form:null,
      open:false,
      activeName:'0',
      unDoneNum:'',
      doingNum:'',
      doneNum:'',
      rejectNum:'',
     

      fileList:[],
      // 遮罩层
      loading: false,

      //弹出框遮盖层
      dialogLoading:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //项目列表
      taskList: [],
      // 弹出层标题
      title: "",
      //行号
      lineNo:0,
      upload: {
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + '/business/sys-files/upload/other'
      },
 
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNo: null,
        taskNo: null,
        overdue:null,
        flag:0,
        productType:null,
        productLine:null

      },
      form:{
        remark:null,
        fileIds:[],
        projectNodeMemberId:null
      },
      param:{},
      rules:{
        attachment: [
            { required: true, message: "附件不能为空", trigger: "blur" }
          ] 
        } 
    };
  },

 
  created() {
     
    if(this.$route.query.projectNo!=null ){
      this.queryParams.projectNo = this.$route.query.projectNo;
    }


    this.getList();


    this.queryParams.flag = 0 ;
    getTaskList(this.queryParams).then(response => { 
        this.unDoneNum ='未完成('+ response.total+')';
         
    });


    this.queryParams.flag = 1 ;
    getTaskList(this.queryParams).then(response => { 
        this.rejectNum ='驳回('+ response.total+')'; 
    });
    
    this.queryParams.flag = 2 ;
    getTaskList(this.queryParams).then(response => { 
        this.doingNum ='审核中('+ response.total+')'; 
    });

    this.queryParams.flag = 3 ;
    getTaskList(this.queryParams).then(response => { 
        this.doneNum ='已完成('+ response.total+')'; 
    });

    this.queryParams.flag = 0;
 
  },
 
  methods: {

    //绑定PLM文件弹框
    handleRePLMFile(row){
      this.$refs.bindPlmFile.open(row);
    },

    //切换状态
    handleClick(obj){  
        this.queryParams.flag = obj;
        this.getList();
    },


    //文件上传成功回调
    handleUploadSuccess(response, file, fileList){
      this.form.fileIds.push(response.data.id);
      this.fileList = fileList;
      this.dialogLoading = false;
    },


    //文件上传中会回调
    handleUploadProgress(){
        this.dialogLoading = true;
    },

    //提交
    onSubmit(){


      this.dialogLoading = true;
      processAdd(this.form).then(response => {
        this.getList();
        this.dialogLoading = false;
        this.closeOpen();
      });
    },
 

    //项目详情
    openViewDetail(row){
      row.id = row.projectListId;
      this.$nextTick(() => {
        this.$router.push({
          path: "ProjectDetail",
          query: row
        })
      })

    },
 
 
    /** 查询项目列表 */
    getList() {
      this.queryParams.exportFlag=null
      this.loading = true;
      getTaskList(this.queryParams).then(response => {
        this.taskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
 
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
 
     
 
    /** 删除按钮操作 */
    handleCreateOA(row) {
      this.title = '发起OA',
      this.form.projectNodeMemberId = row.id,
      this.open = true;
    },

    closeOpen(){
      this.open = false;
      this.reset();
     
    },

    reset(){
      this.form.remark = null;
      this.form.projectNodeMemberId = null;
      this.form.fileIds = [];
      this.fileList  = [];
 
    }

  }
};
</script>
<style scoped>
.el-col {
  height: 60px;
}

.labelword ::v-deep .el-form-item__label {
  white-space: pre-line !important;
  line-height: 15px !important;
}

.el-table .danger-row {
  background: rgb(187, 179, 184);
}

.el-table .success-row {
  background: #00FF00;
}


::v-deep .table_header_row{
  background-color:#ffffff !important;

}
</style>
